package cn.kjcoder.redis.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hkj
 * @email 1349091387@qq.com
 * @date 2022/1/19
 * 源码允许修改，并且本人十分乐意有 大佬 来对代码进行 随 意 调 教
 **/
@RestController
@Slf4j
public class ViewController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/view")
    public void view(Integer id){
        String key = "article:" + id;
        //计数器，每次自增一
        Long count = this.stringRedisTemplate.opsForValue().increment(key, 2L);
        log.info("key={}，阅读量={}",key,count);
    }
}
